package org.hadoop.input.db;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class StudWritable implements DBWritable, Writable {
    private Integer id;
    private String name;
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(id);
        out.writeUTF(name);
    }
    @Override
    public void readFields(DataInput in) throws IOException {
        id = in.readInt();
        name =in.readUTF();
    }
    @Override
    public void write(PreparedStatement statement) throws SQLException {
            statement.setInt(1,id);
            statement.setString(1,name);
    }
    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        id = resultSet.getInt("id");
        name = resultSet.getString("name");
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
